<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Testing PCRE</title>
</head>
<body>
<?php // Script 13.1 - pcre.php

// This script takes a submitted string and checks it against s submitted pattern.

if (isset($_POST['submitted'])) {
	
	// Trim the strings:
	$pattern = trim($_POST['pattern']);
	$subject = trim($_POST['subject']);
	
	// Print a caption:
	echo "<p>The result of checking <br/><b>$pattern</b><br/>againgst<br/>$subject<br/>is ";
	
	// Test:
	if (preg_match($pattern, $subject)) {
		echo 'TRUE!</p>';
	} else {
		echo 'FALSE!</p>';
	}
	
} // End of submission IF.

// Display the HTML form.
?>
<form action="pcre.php" method="post">
	<p>Regular Expression Pattern: <input type="text" name="pattern" value="<?php if(isset($pattern)) echo $pattern; ?>" size="30"/>(include the delimiters)</p>
	<p>Test Subject: <input type="text" name="subject" value="<?php if (isset($subject)) echo $subject; ?>" size="30"/></p>
	<input type="submit" name="submit" value="Test!"/>
	<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>